<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Admin_Login extends Controller_Admin_Base
{
    protected $need_auth = false;
    
    public function action_login()
    {        
        if (HTTP_Request::POST == $this->request->method()) {
            $email    = $this->request->post('email');
            $password = $this->request->post('password');
                  
            try {
                Model_Auth::instance()->login($email, $password, true);                
                $_POST = array(); 
                if (Model_Auth::instance()->logged_in(Model_User_Shop::ROLE_ADMINISTRATOR)) {
                    Request::current()->redirect(Helper_Admin::get_url());    
                }                        
            } catch (Model_Exception $e) {
                $this->add_message($e->getMessage());
            }
        }
        $content = new View('admin/login/login_tpl');       
        $this->print_template('Авторизация', $content); 
    }
    
    public function action_logout()
    {
        Model_Auth::instance()->logout();
        Request::current()->redirect(Helper_Admin::get_url().'/login');    
    }
    
} 
